home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / tftp / defs.h < prev    next >
C/C++ Source or Header  |  1989-12-17  |  4KB  |  129 lines

  1. /*
  2.  * Definitions for TFTP client and server.
  3.  */
  4.  
  5. #include    <stdio.h>
  6. #include    <sys/types.h>
  7. #include    <setjmp.h>
  8.  
  9. #include    "systype.h"
  10.  
  11. #define    MAXBUFF         2048    /* transmit and receive buffer length */
  12. #define    MAXDATA          512    /* max size of data per packet to send or rcv */
  13.                 /* 512 is specified by the RFC */
  14. #define    MAXFILENAME      128    /* max filename length */
  15. #define    MAXHOSTNAME      128    /* max host name length */
  16. #define    MAXLINE          512    /* max command line length */
  17. #define    MAXTOKEN      128    /* max token length */
  18.  
  19. #define    TFTP_SERVICE    "tftp"    /* name of the service */
  20. #define    DAEMONLOG    "/tmp/tftpd.log"
  21.                 /* log file for daemon tracing */
  22.  
  23. /*
  24.  * Externals.
  25.  */
  26.  
  27. extern char    command[];    /* the command being processed */
  28. extern int    connected;    /* true if we're connected to host */
  29. extern char    hostname[];    /* name of host system */
  30. extern int    inetdflag;    /* true if we were started by a daemon */
  31. extern int    interactive;    /* true if we're running interactive */
  32. extern jmp_buf    jmp_mainloop;    /* to return to main command loop */
  33. extern int    lastsend;    /* #bytes of data in last data packet */
  34. extern FILE    *localfp;    /* fp of local file to read or write */
  35. extern int    modetype;    /* see MODE_xxx values */
  36. extern int    nextblknum;    /* next block# to send/receive */
  37. extern char    *pname;        /* the name by which we are invoked */
  38. extern int    port;        /* port number - host byte order */
  39.                     /* 0 -> use default */
  40. extern char    *prompt;    /* prompt string, for interactive use */
  41. extern long    totnbytes;    /* for get/put statistics printing */
  42. extern int    traceflag;    /* -t command line option, or "trace" cmd */
  43. extern int    verboseflag;    /* -v command line option */
  44.  
  45. #define    MODE_ASCII    0    /* values for modetype */
  46.                 /* ascii == netascii */
  47. #define    MODE_BINARY    1    /* binary == octet */
  48.  
  49. /*
  50.  * One receive buffer and one transmit buffer.
  51.  */
  52.  
  53. extern char    recvbuff[];
  54. extern char    sendbuff[];
  55. extern int    sendlen;    /* #bytes in sendbuff[] */
  56.  
  57. /*
  58.  * Define the tftp opcodes.
  59.  */
  60.  
  61. #define    OP_RRQ        1    /* Read Request */
  62. #define    OP_WRQ        2    /* Write Request */
  63. #define    OP_DATA        3    /* Data */
  64. #define    OP_ACK        4    /* Acknowledgment */
  65. #define    OP_ERROR    5    /* Error, see error codes below also */
  66.  
  67. #define    OP_MIN        1    /* minimum opcode value */
  68. #define    OP_MAX        5    /* maximum opcode value */
  69.  
  70. extern int    op_sent;    /* last opcode sent */
  71. extern int    op_recv;    /* last opcode received */
  72.  
  73. /*
  74.  * Define the tftp error codes.
  75.  * These are transmitted in an error packet (OP_ERROR) with an
  76.  * optional netascii Error Message describing the error.
  77.  */
  78.  
  79. #define    ERR_UNDEF    0    /* not defined, see error message */
  80. #define    ERR_NOFILE    1    /* File not found */
  81. #define    ERR_ACCESS    2    /* Access violation */
  82. #define    ERR_NOSPACE    3    /* Disk full or allocation exceeded */
  83. #define    ERR_BADOP    4    /* Illegal tftp operation */
  84. #define    ERR_BADID    5    /* Unknown TID (port#) */
  85. #define    ERR_FILE    6    /* File already exists */
  86. #define    ERR_NOUSER    7    /* No such user */
  87.  
  88. /*
  89.  * Debug macros, based on the trace flag (-t command line argument,
  90.  * or "trace" command).
  91.  */
  92.  
  93. #define    DEBUG1(fmt, arg1)    if (traceflag) { \
  94.                     fprintf(stderr, fmt, arg1); \
  95.                     fputc('\n', stderr); \
  96.                     fflush(stderr); \
  97.                 } else ;
  98.  
  99. #define    DEBUG2(fmt, arg1, arg2)    if (traceflag) { \
  100.                     fprintf(stderr, fmt, arg1, arg2); \
  101.                     fputc('\n', stderr); \
  102.                     fflush(stderr); \
  103.                 } else ;
  104.  
  105. /*
  106.  * Define macros to load and store 2-byte integers, since these are
  107.  * used in the TFTP headers for opcodes, block numbers and error
  108.  * numbers.  These macros handle the conversion between host format
  109.  * and network byte ordering.
  110.  */
  111.  
  112. #define ldshort(addr)        ( ntohs (*( (u_short *)(addr) ) ) )
  113. #define    stshort(sval,addr)    ( *( (u_short *)(addr) ) = htons(sval) )
  114.  
  115. #ifdef    lint        /* hush up lint */
  116. #undef    ldshort
  117. #undef    stshort
  118. short    ldshort();
  119. #endif    /* lint */
  120.  
  121. /*
  122.  * Datatypes of functions that don't return an int.
  123.  */
  124.  
  125. char    *gettoken();
  126. FILE    *file_open();
  127. double    t_getrtime();    /* our library routine to return elapsed time */
  128. char    *sys_err_str();    /* our library routine for system error messages */
  129.